package com.lihh.rocket5.normal;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.io.UnsupportedEncodingException;

public class OneWayProducer {
  public static void main(String[] args) throws MQClientException, UnsupportedEncodingException, RemotingException, InterruptedException {
    // 实例化 producer
    DefaultMQProducer producer = new DefaultMQProducer("group_test");
    // 设置 name server
    producer.setNamesrvAddr("localhost:9876");
    // 开启 实例
    producer.start();
    
    for (int i = 0; i < 10; i++) {
      String msg = "one way .. " + (i + 1);
      Message message = new Message("order001", "TagA", msg.getBytes(RemotingHelper.DEFAULT_CHARSET));
      producer.sendOneway(message);
    }
    
    producer.shutdown();
  }
}
